package tmp;

import lombok.Data;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by dycong on 2017/3/21.
 */
@Data
public class CcbProduct {

    String skuId;
    String id;
    String name;
    String description;
    int price;

    int buyCount;
    int discount;

    String image;

    String vendorId;
    int stock;

    /**
     * 01  未审核02  审核中
     * 03  已删除04  待上架
     * 05  已上架
     * 06 审核未通过
     */
    int status;

    /**
     * TODO 当一个JSONArray里的item(JSONObject)包含一个JSONArray时（eg:上例为JSON一个元素时）时对这个里JSONArray需要匹配一个Class,以item名为key,以对应的class为value放入Map传入
     * TODO 对应Object里包含数组或集合(数组或集合对应JSONArray[{},{}]，单个对象Object对应内部json{}),内部JSONArray时需要ClassMap,JSONObject是不需要ClassMap
     * TODO ObjectMapper不需要这么做
     * @param args
     */
    public static void main(String[] args) {
//        String str = "[{\"orderId\":\"201703200049615819\",\"status\":\"WAIT_SELLER_SEND_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489991517000,\"paymentTime\":1489991535000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703200049615131\",\"status\":\"WAIT_BUYER_CONFIRM_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489990595000,\"paymentTime\":1489990656000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703200049615124\",\"status\":\"WAIT_BUYER_PAY\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489990524000,\"paymentTime\":null,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703200049600248\",\"status\":\"WAIT_BUYER_CONFIRM_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489976433000,\"paymentTime\":1489976454000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703200049590487\",\"status\":\"WAIT_SELLER_SEND_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489972787000,\"paymentTime\":1489972809000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703200049590465\",\"status\":\"WAIT_BUYER_CONFIRM_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489972291000,\"paymentTime\":1489972373000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703170049502597\",\"status\":\"WAIT_BUYER_CONFIRM_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489717355000,\"paymentTime\":1489717382000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703170049502555\",\"status\":\"WAIT_BUYER_CONFIRM_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489716890000,\"paymentTime\":1489716917000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703170049499207\",\"status\":\"WAIT_BUYER_CONFIRM_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489715715000,\"paymentTime\":1489715739000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703170049497748\",\"status\":\"WAIT_BUYER_CONFIRM_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489714802000,\"paymentTime\":1489714825000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703170049497744\",\"status\":\"WAIT_BUYER_PAY\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489714745000,\"paymentTime\":null,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703160049478935\",\"status\":\"WAIT_BUYER_CONFIRM_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489652619000,\"paymentTime\":1489652643000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703160049478911\",\"status\":\"WAIT_BUYER_CONFIRM_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489652332000,\"paymentTime\":1489652353000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703160049476601\",\"status\":\"WAIT_BUYER_CONFIRM_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489651525000,\"paymentTime\":1489651608000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703090049204573\",\"status\":\"WAIT_SELLER_SEND_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489046373000,\"paymentTime\":1489046402000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]},{\"orderId\":\"201703090049202817\",\"status\":\"WAIT_SELLER_SEND_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489044929000,\"paymentTime\":1489045016000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":[{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}]}]";
//        JSONArray jsonArray = JSONArray.fromObject(str);
//        Object o = JSONArray.toArray(jsonArray, CcbOrder.class);
//        Map<String, Class> map = new HashMap<>();
//        map.put("productItems", CcbProduct.class);
//        Object o1 = JSONArray.toCollection(jsonArray, CcbOrder.class);
//        Object o2 = JSONArray.toArray(jsonArray, CcbOrder.class, map);

        String sub="{\"orderId\":\"201703200049615819\",\"status\":\"WAIT_SELLER_SEND_GOODS\",\"memo\":\"\",\"buyerEmail\":\"\",\"buyerName\":\"李宁东\",\"buyerId\":\"CCBB2CEPAY2016110208569754\",\"orderTime\":1489991517000,\"paymentTime\":1489991535000,\"amountFen\":1,\"payFen\":1,\"couponFen\":0,\"merchantDiscountFen\":0,\"deliveryFeeFen\":0,\"shipInfo\":{\"name\":\"李宁东\",\"province\":\"广东\",\"city\":\"深圳市\",\"country\":\"南山区\",\"address\":\"科兴科学园A4605\",\"zip\":\"518000\",\"mobile\":\"13026680546\",\"phone\":\"\"},\"productItems\":{\"skuId\":\"\",\"id\":\"0001825620\",\"name\":\"自行车坐垫\",\"description\":\"\",\"price\":1,\"buyCount\":1,\"discount\":0,\"image\":\"http://image1.buy.ccb.com/merchant/201603/340858370/1478768244643_1.jpg\",\"vendorId\":null,\"stock\":0,\"status\":0}}";
        JSONObject jsonObject=JSONObject.fromObject(sub);
        Object o = JSONObject.toBean(jsonObject, CcbOrder.class);
        Map<String, Class> map = new HashMap<>();
        map.put("productItems", CcbProduct.class);
        Object o1 = JSONObject.toBean(jsonObject, CcbOrder.class);
        Object o2 = JSONObject.toBean(jsonObject, CcbOrder.class, map);

        System.out.println(o);

    }
}
